package com.open4cn.simulator.connect.com.handler;

import com.open4cn.simulator.core.connector.serialport.SerialPortHandlerContext;
import com.open4cn.simulator.core.connector.serialport.SerialPortInboundHandlerAdapter;
import com.open4cn.simulator.core.parser.InstructionParserChain;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-06-11 23:33
 */
public class DispatcherHandler extends SerialPortInboundHandlerAdapter {

    // 指令分析链
    private InstructionParserChain chain;

    public DispatcherHandler(InstructionParserChain chain) {
        this.chain = chain;
    }

    @Override
    public void serialPortRead(SerialPortHandlerContext ctx, Object msg) {
        Object result = chain.filter(msg);
        ctx.fireRead(result);
    }

}
